/*jshint esversion: 9 */
//常用的其他工具
export function getColorByState(state){  //根据状态获取字体颜色
    switch(true){
        case 
            state==="申报中" 
            || state==="已作废"
            || state==="已打回":
            return "rgb(241 46 46)";  //红色
        case 
            state==="已申报" 
            || state==="待审核" 
            || state==="在处理" 
            || state==="公示中" 
            || state==="未上传"
            || state==="待分配"
            || state==="待接单":
            return "rgb(255 162 0)";  //黄色
        case 
            state==="已截止":
            return "#dbd8db";  //灰色
        case 
            state==="已完结" 
            || state==="已公布"
            || state==="已通过":
            return "rgb(98 177 77)";  //绿色
    }
}
export function getBgColorByState(state){  //根据状态获取背景颜色
    switch(true){
        case 
            state==="申报中" 
            || state==="已作废"
            || state==="已打回":
            return "#fff2f2";  //红色
        case 
            state==="已申报" 
            || state==="待审核" 
            || state==="在处理" 
            || state==="公示中" 
            || state==="未上传"
            || state==="待分配"
            || state==="待接单":
            return "#fff9eb";  //黄色
        case 
            state==="已截止":
            return "#f5f5f5";  //灰色
        case 
            state==="已完结" 
            || state==="已公布"
            || state==="已通过":
            return "#eeffe6";  //绿色
    }
}
export function formatFileSize(fileSize) {  //格式化文件大小
    if(!fileSize) return fileSize;
    if(typeof fileSize !== 'number') return fileSize;
    var temp;
    if (fileSize < 1024) {
        return fileSize + 'B';
    } else if (fileSize < (1024*1024)) {
        temp = fileSize / 1024;
        temp = temp.toFixed(2);
        return temp + 'KB';
    } else if (fileSize < (1024*1024*1024)) {
        temp = fileSize / (1024*1024);
        temp = temp.toFixed(2);
        return temp + 'MB';
    } else {
        temp = fileSize / (1024*1024*1024);
        temp = temp.toFixed(2);
        return temp + 'GB';
    }
}
export function getFilePreviewState(fileName){  //判断文件是否可预览
    let types = fileName.split('.');
    let type = types[types.length - 1];
    return 'png|jpg|pdf'.indexOf(type) !== -1;
}
export function flattenTwoList(list=[]){  //将二维数组展开
    let dataList = [];
    for(let item of list){
        dataList.push(...item);
    }
    return dataList;
}
export function getFileType(fileName){  //获取文件类型
    if(!fileName) return fileName;
    let types = fileName.split('.');
    return types[types.length - 1];
}
export function randomString(e) {  //随机获取相应位数的字符串
    e = e || 32;
    let t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
    a = t.length,
    n = "";
    for (let i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
    return n
}
export function highlightFilter(text,hlText){  //高亮文本过滤器
    if(!text || !hlText) return text;
    return text.replace(new RegExp(hlText,'g'),`<span>${hlText}</span>`);
}
export function isWeiXin(){  //判断是否是微信浏览器
    let ua = navigator.userAgent.toLowerCase();  
    if(ua.match(/MicroMessenger/i)=="micromessenger") {  
        return true;  
    } else {  
        return false;  
    }  
}
export function delHtmlTag(str){  //字符串去掉所有的html标记
    if(!str) return str;
    return str.replace(/<[^>]+>/g,"");
}
export function randomColor(){  //获取随机颜色
    let color="#";
    const colorArr=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
    const random = (min,max)=>(Math.random() * (max - min) | 0) + min;
    for(var i=0;i<6;i++){
        color += colorArr[random(0,16)];
    }
    return color;
}